/**
 * 
 */
package pl.kkalisz.android.model.error;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;

/**
 * @author kkalisz
 *
 */
public abstract class uException extends Exception{
    
    
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
     * 
     */
    public uException(String msg) {
        super(msg);
    }
    
    
    
    public void printStackTrace(final Context aContext)
    {
        
        super.printStackTrace(); 
        final AlertDialog aDialog = new AlertDialog.Builder(aContext).setMessage(this.getMessage()).setTitle(getTittle())
                .setNeutralButton("Close", new OnClickListener() {
                  public void onClick(final DialogInterface dialog, final int which) 
                  {
                     dialog.dismiss();
                     if(closeAfterException()) ((Activity) aContext).finish();
                                 
                  }
                }).create();
        aDialog.show();
    }
    
    
    /**
     * @return class name ex. BngException
     */
    public String getTittle()
    {
        return this.getClass().getSimpleName();
        
    }
    
    /**
     * @return true if program should close after execution of exceptionDialog
     */
    public abstract boolean closeAfterException();

}
